<?php
/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2018/11/28
 * Time: 16:06
 */

namespace app\api\model;


use think\Model;

class Notice extends Model
{
    protected $autoWriteTimestamp = 'datetime';
    protected $updateTime = false;

    /**
     * @desc  评论通知详情
     * @param $belongid  消息所属人id
     * @return $re  array  所属人所有消息集合
     */
    public static function getevalutenotice($belongid){
        $re=self::with('user')
            ->where('belongid',$belongid)
            ->where('type',3)
            ->where('status','0')
            ->order('create_time desc')
            ->field('type,belongid,status,create_time',true)
            ->select();
        return $re;
    }

    /**
     * @desc  新增评论消息
     * @param $replyid   int 评论id
     * @param $type      int 消息类型
     * @param $userid    int 发起消息人id
     * @param $belongid  int 消息所属人id
     * @return $re       新增消息sql结果
     */
    public static function addevalutenotice($replyid,$txt,$userid,$belongid)
    {
        $re=self::create([
           'replyid'=>$replyid,
           'txt'=>$txt,
           'type'=>3,
           'userid'=>$userid,
           'belongid'=>$belongid,
           'status'=>0
        ]);
        return $re;
    }

    /**
     * @desc  删除已失效的消息
     * @param $replyid   int 评论id
     * @param $type      int 消息类型
     * @param $userid    int 发起消息人id
     * @param $belongid  int 消息所属人id
     * @return $re       删除消息sql结果
     */
    public static function delevalutenotice($replyid,$txt,$userid,$belongid)
    {
        $re=self::where('replyid',$replyid)
                ->where('txt',$txt)
                ->where('type',3)
                ->where('userid',$userid)
                ->where('belongid',$belongid)
                ->delete();
        return $re;
    }
    public function user(){
        return $this->belongsTo('User','userid','id')->field('id,name,photo');
    }
}